package com.lagou.config;

import org.springframework.web.WebApplicationInitializer;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.servlet.DispatcherServlet;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRegistration;
import javax.servlet.annotation.HandlesTypes;

/*实现了onStartup后，在运行中会自动执行该方法，也正是该方法替代了spring中的web.xml，实现了无配置*/
public class MyWebApplicationInitializer extends MyServlet implements WebApplicationInitializer {
    @Override
    public void onStartup(ServletContext servletContext) throws ServletException {
        // 将DispatcherServlet添加到tomcat上下文中去
        ServletRegistration.Dynamic registration = servletContext.addServlet("app", super.getDispatcherServlet());
        if (registration != null) {
            registration.setLoadOnStartup(1);
            registration.addMapping("/app/*");
        }
    }
}
